<?php
/***************************************************************
 *  Copyright notice
 *
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General protected License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General protected License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General protected License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 *
 * @version $Id:$
 * @license http://opensource.org/licenses/gpl-license.php GNU protected License, version 2
 */
class Tx_IfpCurriculum2_Service_PDFService extends Tx_Extbase_MVC_Controller_ActionController {


	
/**
 * 
 * Enter description here ...
 * @param string $templateName
 * @param array $variables
 */
	protected function init(){
		require_once(t3lib_extMgm::extPath($_EXTKEY) . "/Classes/Service/pdf/dompdf_config.inc.php");
	}
	
	public function generatePDF($templateName, array $variables = array()) {
		require_once(t3lib_extMgm::extPath($_EXTKEY) . "/Classes/Service/pdf/dompdf_config.inc.php");
		$pdfView = $this->objectManager->create('Tx_Fluid_View_StandaloneView');
		$pdfView->setFormat('print');
		$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
		$templateRootPath = t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
		$templatePathAndFilename = $templateRootPath . 'PDF/' . $templateName . '.print';
		$pdfView->setTemplatePathAndFilename($templatePathAndFilename);
		$pdfView->assignMultiple($variables);
		$pdfView = $pdfView->render();
		 
		$dompdf = new DOMPDF();
  		$dompdf->load_html($pdfView);
  		$dompdf->set_paper("a4", "portrait");
  		$dompdf->render();

  	$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
 	 exit(0);
		
		
	}
}

?>